package com.mdd.admin.controller.customer;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.ICustomerTermRuleService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.CustomerTermRuleCreateValidate;
import com.mdd.admin.validate.CustomerTermRuleUpdateValidate;
import com.mdd.admin.validate.CustomerTermRuleSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.CustomerTermRuleListedVo;
import com.mdd.admin.vo.CustomerTermRuleDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/customerTermRule")
@Api(tags = "客户期限规则管理")
public class CustomerTermRuleController {

    @Resource
    ICustomerTermRuleService iCustomerTermRuleService;

    @GetMapping("/list")
    @ApiOperation(value="客户期限规则列表")
    public AjaxResult<PageResult<CustomerTermRuleListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated CustomerTermRuleSearchValidate searchValidate) {
        PageResult<CustomerTermRuleListedVo> list = iCustomerTermRuleService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="客户期限规则详情")
    public AjaxResult<CustomerTermRuleDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        CustomerTermRuleDetailVo detail = iCustomerTermRuleService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "客户期限规则新增")
    @PostMapping("/add")
    @ApiOperation(value="客户期限规则新增")
    public AjaxResult<Object> add(@Validated @RequestBody CustomerTermRuleCreateValidate createValidate) {
        iCustomerTermRuleService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户期限规则编辑")
    @PostMapping("/edit")
    @ApiOperation(value="客户期限规则编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody CustomerTermRuleUpdateValidate updateValidate) {
        iCustomerTermRuleService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "客户期限规则删除")
    @PostMapping("/del")
    @ApiOperation(value="客户期限规则删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iCustomerTermRuleService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
